package com.hopedove.workshop.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.hopedove.workshop.data.pojo.ObservableShiftRecordItem
import com.hopedove.workshop.databinding.WorkshopShiftChangeRecordItemBinding

class ShiftChangeRecordAdapter : RecyclerView.Adapter<ShiftChangeRecordAdapter.VH>() {

    private val dataSet = mutableListOf<ObservableShiftRecordItem>()

    fun setData(list: List<ObservableShiftRecordItem>) {
        dataSet.clear()
        dataSet.addAll(list)
        notifyDataSetChanged()
    }

    class VH(val binding: WorkshopShiftChangeRecordItemBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val binding = WorkshopShiftChangeRecordItemBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return VH(binding)
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.binding.item = dataSet[position]
    }

    override fun getItemCount() = dataSet.size
}